package com.itheima.controller;


import com.itheima.common.entity.Result;
import com.itheima.pojo.Setmeal;
import com.itheima.service.SetmealService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/setmeal")
@Slf4j
@Api(tags = "体检套餐")
public class SetmealController {

    @Autowired
    private SetmealService setmealService;


    /**
     * author: MaShuNing
     * 查询所有套餐
     * @return
     */
    @PostMapping("/getSetmeal")
    @ApiOperation("查询所有套餐")
    public Result getSetmeal(){
        log.info("查询所有套餐");
        List<Setmeal> setmealAll = setmealService.getSetmealAll();
        return new Result(true,"查询所有套餐成功",setmealAll);
    }

    @GetMapping("/getSetmeal")
    @ApiOperation("查询所有套餐")
    public String getSetmeal(Model model){
        log.info("查询所有套餐");
        List<Setmeal> setmealAll = setmealService.getSetmealAll();

        model.addAttribute("setmealAll", setmealAll);
        return "setmeal";

//        return new Result(true,"查询所有套餐成功",setmealAll);
    }




    /**
     * author: MaShuNing
     * 根据套餐id查询套餐
     * @param id
     * @return
     */
    @PostMapping("/findById")
    @ApiOperation("根据套餐id查询套餐")
    public Result findById(Integer id){
        log.info("根据套餐id查询套餐");
        Setmeal setmeal = setmealService.findById(id);
        return new Result(true,"根据套餐id查询套餐成功",setmeal);
    }


}
